package com.sxhuayuan.parking.entity;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

import org.hibernate.validator.constraints.Length;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * 停车场管理用户
 * 
 * @author 何龙
 * @create 2019-04-19 9:30
 */
@Entity
@Table(name = "hypk_parking_lot_user")
public class ParkingLotUser extends BaseEntity {

	/** 用户名 */
	private String username;

	/** 密码 */
	private String password;

	/** 退款密码 */
	private String refundPass;

	/** 姓名 */
	private String name;

	/** 是否启用 */
	private Boolean isEnabled = true;

	/** 是否锁定 **/
	private Boolean isLocked = false;

	/** 最后登录日期 */
	private Date loginDate;

	/** 最后登录IP */
	private String loginIp;

	/** 对应的多个车场 */
	private Set<ParkingLot> parkingLots;

	/** 角色 */
	private Set<Role> roles = new HashSet<>();

	/**
	 * 获取用户名
	 *
	 * @return 用户名
	 */
	@NotEmpty(groups = Save.class)
	@Pattern(regexp = "^[0-9a-z_A-Z\\u4e00-\\u9fa5]+$")
	@Length(min = 2, max = 20)
	@Column(nullable = false, unique = true, length = 100)
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 * 获取密码
	 *
	 * @return 密码
	 */
	@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
	@NotEmpty(groups = Save.class)
	@Pattern(regexp = "^[^\\s&\"<>]+$")
	@Length(min = 4, max = 64)
	@Column(nullable = false)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * 获取姓名
	 *
	 * @return 姓名
	 */
	@Length(max = 100)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 获取是否启用
	 *
	 * @return 是否启用
	 */
	@NotNull
	@Column(nullable = false)
	public Boolean getIsEnabled() {
		return isEnabled;
	}

	/**
	 * 获取是否锁定
	 *
	 * @return 是否锁定
	 */
	@NotNull
	@Column(nullable = false)
	public Boolean getIsLocked() {
		return isLocked;
	}

	public void setIsLocked(Boolean isLocked) {
		this.isLocked = isLocked;
	}

	public void setIsEnabled(Boolean isEnabled) {
		this.isEnabled = isEnabled;
	}

	public Date getLoginDate() {
		return loginDate;
	}

	public void setLoginDate(Date loginDate) {
		this.loginDate = loginDate;
	}

	public String getLoginIp() {
		return loginIp;
	}

	public void setLoginIp(String loginIp) {
		this.loginIp = loginIp;
	}

	/**
	 * 获取角色
	 *
	 * @return 角色
	 */
	@NotEmpty
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "hypk_parking_lot_role")
	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	public String getRefundPass() {
		return refundPass;
	}

	public void setRefundPass(String refundPass) {
		this.refundPass = refundPass;
	}

	@NotEmpty
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "hypk_parking_lot_user_parking")
	public Set<ParkingLot> getParkingLots() {
		return parkingLots;
	}

	public void setParkingLots(Set<ParkingLot> parkingLots) {
		this.parkingLots = parkingLots;
	}

}
